********************************************************************************
********"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*****
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019, case(lower)
run RO_creditregister tm(2019m2) tm(2020m2) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(e10 e14 e13 e12 dtop66e14 dmid6633e14 exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2019m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

gen post=(time>=tm(2019m9))
gen poste14=post*e14
gen poste10=post*e10
gen postdtop66e14=post*dtop66e14
gen postdmid6633e14=post*dmid6633e14
gen postexlnassets=post*exlnassets
gen postexcashas=post*excashas

reghdfe $y poste10 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix OVERALL=r(table)
reghdfe $y poste14 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix MMA=r(table)
reghdfe $y postdtop66e14 postdmid6633e14 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix MMAD=r(table)

matrix TOTAL2019=(OVERALL[1,1],OVERALL[5,1],OVERALL[6,1]\MMA[1,1],MMA[5,1],MMA[6,1]\MMAD[1,1],MMAD[5,1],MMAD[6,1])
svmat TOTAL2019, names(model)
rename model1 coef
rename model2 lb
rename model3 ub
gen x=_n
keep x coef lb ub
keep if x<=3
drop x
gen x=1
replace x=x[_n-1]+2 if _n!=1

**#Bookmark (output - panel a)
twoway (bar coef x if x!=5, col(gs8) barwidth(0.5)) (bar coef x if x==5, yaxis(2) col(gs8) barwidth(0.5)) (rcap lb ub x if x!=5, col(black) lw(medthick)) (rcap lb ub x if x==5, col(black) lw(medthick) yaxis(2)) (scatter coef x if x!=5, col(black) msize(big) mlabel(coef)  mlabposition(1) mlabformat(%9.3fc) mlabc(black))  (scatter coef x if x==5, yaxis(2) col(black) msize(big) mlabel(coef)  mlabposition(1) mlabformat(%9.3fc) mlabc(black))  , ylabel(-0.08(0.04)0.2) ylabel(-0.6(0.3)1.5, axis(2)) xtitle("") ytitle("Lending growth, monthly") ytitle("Lending growth, monthly", axis(2)) xlabel(0 " " 1 "(1)" 2 " " 3 "(2)" 4 " " 5 "(3)" 6 " ", notick) xscale(alt) legend(off) yline(0, lcol(gs5) lp(solid)) plotregion(lcolor(black)) text(-0.02 1 "Broad", size(small)) text(0.15 3 "Mark-to-market", size(small))  text(0.195 5 "Mark-to-market, dummy" "(right axis)", size(small)) saving($outputdirectory/FIG3A, replace)

********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global y2 "lncdisbur_2w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e10 e13 dtop85e13 exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

gen post=(time>=tm(2015m1))
gen poste13=post*e13
gen poste10=post*e10
gen postdtop85e13=post*dtop85e13
gen postexlnassets=post*exlnassets
gen postexcashas=post*excashas

gen count=1 if time==tm(2015m1)
recode count (.=0)
egen impulse=sum(count), by(id)
winsor2 lncdisbur if lncdisbur!=.&impulse==1, suffix(_2w199) cuts(1 99)
keep if impulse==1

reghdfe $y2 poste10 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix OVERALL=r(table)
reghdfe $y2 poste13 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix MMA=r(table)
reghdfe $y2 postdtop85e13 lncrefin postexlnassets postexcashas $regcommands level(90)
matrix MMAD=r(table)

matrix TOTAL2015=(OVERALL[1,1],OVERALL[5,1],OVERALL[6,1]\MMA[1,1],MMA[5,1],MMA[6,1]\MMAD[1,1],MMAD[5,1],MMAD[6,1])
svmat TOTAL2015, names(model)
rename model1 coef
rename model2 lb
rename model3 ub
gen x=_n
keep x coef lb ub
keep if x<=3
drop x
gen x=1
replace x=x[_n-1]+2 if _n!=1

**#Bookmark (output - panel b)
twoway (bar coef x if x==5, yaxis(2) col(gs8) barwidth(0.5)) (bar coef x if x!=5, col(gs8) barwidth(0.5))  (rcap lb ub x if x!=5, col(black) lw(medthick)) (rcap lb ub x if x==5, col(black) lw(medthick) yaxis(2)) (scatter coef x if x!=5, col(black) msize(big) mlabel(coef) mlabposition(2) mlabformat(%9.3fc) mlabc(black)) (scatter coef x if x==5, yaxis(2) col(black) msize(big) mlabel(coef)  mlabposition(2) mlabformat(%9.3fc) mlabc(black)) , ylabel(-0.08(0.04)0.2) ylabel(-0.5(0.25)1.25, axis(2)) xtitle("") ytitle("Lending growth, monthly") ytitle("Lending growth, monthly", axis(2)) xlabel(0 " " 1 "(1)" 2 " " 3 "(2)" 4 " " 5 "(3)" 6 " ", notick) xscale(alt) legend(off)  yline(0, lcol(gs5) lp(solid)) graphregion(color(white)) plotregion(lcolor(black)) text(-0.06 1 "Broad", size(small)) text(0.175 3 "Mark-to-market", size(small))  text(0.195 5 "Mark-to-market, dummy" "(right axis)", size(small)) saving($outputdirectory/FIG3B, replace)

